{layout name="layouts/main" /}

<?php

use app\admin\model\field\system\Menu;

$tableClass = new \app\admin\extend\common\html2\Table();
echo $tableClass->addTitle($title);

echo $tableClass->table()->getTable();
$btn = [
	['update','编辑'],
	['del','删除'],
];
echo $tableClass->jsBtn('barDemo',$btn);
echo $tableClass->toolCheckbox('toolStatus', 'status', 'id', '启用|禁用');


?>


<script>
	//表格
	layui.use(['table', 'tableTreeDj'], function() {
		const table = layui.table;
        const tableTree = layui.tableTreeDj
		const form  = layui.form;
		const $ = layui.$;
		const selfLayui = new SelfLayui(layui,$);

		//渲染
		const cols = [[
			{field:'id', title:'<?php echo Menu::id ?>', unresize: true},
			{field:'pid', title:'<?php echo Menu::pid ?>', unresize: true},
			{field:'name', title:'<?php echo Menu::name ?>', width: 200},
			{field:'url', title:'<?php echo Menu::url ?>', width: 350},
			{field:'sort', title:'<?php echo Menu::sort ?>'},
			{field:'icon', title:'<?php echo Menu::icon ?>', templet: function(d) {
					if(!!d.icon) {
						return '<i class="layui-icon '+ d.icon +'" style="font-size: 30px;"></i>';
					}
					return '';
				}},
			{field:'target', title:'<?php echo Menu::target ?>', unresize: true},
			{title:'<?php echo Menu::status ?>', toolbar: '#toolStatus'},
			 {title:'操作', width:200, toolbar: '#barDemo'}
		]];
		const url = './getDataAll';

		const treeConfig = {
			defaultShow: true
			, showCache: true
			, title: 'name'
			, indent: ' &nbsp; &nbsp; &nbsp; &nbsp;'
		}

		tableRender(cols,url,false,1000,false, false, {}, treeConfig);

		//搜索
		const active = {
			reload: function(){
				//执行重载
				const key = {};
				selfLayui.reload(key);
			}
			,del: function(){
				//通过复选框删除
				const url = './batchDel';
				selfLayui.delBatch(url);
			}
			,add:function() {
				//添加
				selfLayui.openAdd('添加<?php echo $title;?>','./add');
			}
		};
		$('.demoTable .layui-btn').on('click', function(){
			const type = $(this).data('type');
			active[type] ? active[type].call(this) : '';
		});

		//监听状态开关
		form.on('switch(toolStatus)', function(data){
			const url = './status';
			selfLayui.changeStatus(url,data);
		});

		//监听工具条
		table.on('tool(test)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
			const data = obj.data; //获得当前行数据
			const layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）

			if(layEvent === 'del'){
				//删除
				const url = './del?id='+obj.data.id;
				selfLayui.del(url);
			} else if(layEvent === 'update'){
				//编辑
				selfLayui.openAdd('编辑<?php echo $title;?>','./update?id='+data.id);
			}
		});
	});
</script>

